<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 2000px;
        }
        .header{
            position: fixed;
            height: 150px;
            width: 100%;
            background-color: #000;
        }
    </style>
</head>
<body>
    <header class="header"></header>

    <script>
        var header = document.querySelector('.header');
        window.onscroll = function () {
            console.log('ss');
            var scrollTop = window.pageYOffset;
            var scale = scrollTop / 300
            if (scrollTop < 300) {
                header.style.opacity = 1 - scale*.5;
                header.style.height = 150 - scale*50 + 'px';
            } else {
                header.style.opacity = 0.5;
                header.style.height = 100 + 'px';
            }
        }
    </script>
</body>
</html>